package com.zgc.simpleholiday.schedule;

import com.zgc.simpleholiday.service.HolidayService;
import lombok.AllArgsConstructor;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
@AllArgsConstructor
public class HolidaySchedule {
    private HolidayService holidayService;

    @Scheduled(cron = "0 0 1 15 * ?")
    public void executeByNextMonth() {
        LocalDate now = LocalDate.now();
        int year = now.getYear();
        int month = now.getMonthValue();
        // 判断是否为十二月份，如果是，则切换到下一年
        if (month == 12) {
            month = 1;
            year++;
        }
        // 触发一下节假日数据持久化
        holidayService.getHolidayByMonth(year + "", month + "");
    }

}
